//
//  ZLTabBarController.m
//  ZLExamination
//
//  Created by Zheng on 2017/8/9.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLTabBarController.h"
#import "ZLBaseNavigationController.h"
#import "ZLHomeViewController.h"
#import "ZLPersonalCenterViewController.h"

@interface ZLTabBarController ()

@property (nonatomic, strong) UIView *maskView; //半透明遮挡视图

@end

@implementation ZLTabBarController

- (void)changeMaskViewHiddenStateWithState:(PKRevealControllerState)state withFinishBlock:(void (^)())block {
    
    [UIView animateWithDuration:kMASK_Duration animations:^{
        if (state == PKRevealControllerShowsLeftViewController) {
            _maskView.hidden = NO;
            _maskView.alpha = kTRANSLUCENT_ALPHA;
        } else if (PKRevealControllerShowsFrontViewController) {
            _maskView.alpha = kZERO_ALPHA;
        }
    } completion:^(BOOL finished) {
        if (state == PKRevealControllerShowsFrontViewController) {
            _maskView.hidden = !_maskView.hidden;
        }
        
        if (block != nil && block != NULL) {
            block();
        }
    }];
}

- (UIView *)maskView {
    if (!_maskView) {
        _maskView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _maskView.backgroundColor = [UIColor lightGrayColor];
        _maskView.alpha = kZERO_ALPHA;
        _maskView.hidden = YES;
    }
    return _maskView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.translucent = NO;
    
    self.tabBar.tintColor = kMY_BLUE_COLOR;
    
    [self.view addSubview:self.maskView];
    self.tabBar.backgroundImage = [UIImage imageNamed:@""];
    
    ZLHomeViewController *homeVC = [[ZLHomeViewController alloc] init];
    ZLBaseNavigationController *homeNav = [[ZLBaseNavigationController alloc] initWithRootViewController:homeVC];
    ZLPersonalCenterViewController *personalVC = [[ZLPersonalCenterViewController alloc] init];
    ZLBaseNavigationController *personalNav = [[ZLBaseNavigationController alloc] initWithRootViewController:personalVC];

    self.viewControllers = @[homeNav,personalNav];
    
    [self setTabBarItemWithController:homeVC withNormalImage:@"home_p_n" withSelectedImage:@"home_p_s" withTitle:@"首页"];
    [self setTabBarItemWithController:personalVC withNormalImage:@"personal_p_n" withSelectedImage:@"personal_p_s" withTitle:@"个人"];
}


- (void)setTabBarItemWithController:(__kindof UIViewController *)vc withNormalImage:(NSString *)normalImg withSelectedImage:(NSString *)seletecdImg withTitle:(NSString *)title {
    UIImage *imageNormal = [[UIImage imageNamed:normalImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *imagePress = [[UIImage imageNamed:seletecdImg] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:imageNormal selectedImage:imagePress];
    vc.tabBarItem.title = title;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
